<?php
namespace Home\Controller;
use Think\Controller;
class XmlsController extends Controller {
    public function index(){
        indexRvent();//测算首页执行事件
        $this->assign('titleName',titleName('Xmls',1));//首页名称

        indexRequest($_REQUEST);//测算首页接收数据处理
        indexInterface('Xmls','XMLS','xmlscs');//首页公共函数

        //渠道获取ID
        $channelID=obtain_channelID('XMLS');
        $this->assign('channelID',$channelID);

        $this->assign('imgPath',cookie('imgPath'));
        $this->assign("orderidnum",'Xmls');
        $this->display("Xmls/ZM_index");
    }
    public function zhifu(){
        $this->assign('titleName',titleName('Xmls',2));//首页名称
        $user_agent = $_SERVER['HTTP_USER_AGENT'];//用户使用的浏览器，操作系统等信息。
        zhifuInterface('Xmls','XMLS',66);//支付页公共

        $channel=cookie('channel');

        if (strpos($user_agent, 'MicroMessenger') == false) {
            //非微信浏览器访问
            if (strpos($user_agent, 'Windows') == true||strpos($user_agent,'Mac') == true) {
                //Windows 电脑访问
                if(channelSaoma($channel)){
                    $this->assign('pc',1);
                    $saomaUrl=wxsaoma('XMLS','姓名灵数',cookie('orderid'));//微信扫码回调参数
                    $this->assign('wxsaoma',$saomaUrl);
                }
            }
        }else{
            $xml=wxgzhzf('XMLS','姓名灵数',cookie('orderid'));//公众号支付回调参数
            $xmlstring = simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA);
            $val = json_decode(json_encode($xmlstring),true);
            $noncestr=noncestr(15);//随机字符串
            $timestamp=time();//时间戳

            $stringA="appId=".cookie('APPID')."&nonceStr={$noncestr}&package=prepay_id={$val['prepay_id']}&signType=MD5&timeStamp={$timestamp}";
            $stringSignTemp=$stringA."&key=".cookie('wxKEY');
            $sign=strtoupper(md5($stringSignTemp));

            $this->assign('timeStamp',$timestamp);
            $this->assign('nonceStr',$noncestr);
            $this->assign('package','prepay_id='.$val['prepay_id']);
            $this->assign('signType','MD5');
            $this->assign('paySign',$sign);
            $this->assign('appId',cookie('APPID'));
        }

        $xingming=cookie('znickname');
        $lenNum=mb_strlen($xingming,'utf-8');
        for($i=0;$i<$lenNum;$i++){
            $xmArr[$i]=mb_substr($xingming,$i,1,'utf-8');
        }
        $pinyinClaa=new \Library\Pinyin();
        foreach($xmArr as $key=>$value){
            $pinyinData=$pinyinClaa->str2pys($value);
            $pyArr[$key]=$pinyinData;
        }
        $dataClass=new \Library\Data();
        $xingmingLs=$dataClass->xingmingLs($pyArr,1);
        $Arr['xingmingLs']=$xingmingLs;
        $this->assign('Arr',$Arr);

        $this->assign('csNameJump',U('Xmls/jieguoye','',false).'?ordernum='.cookie('orderid'));//支付成功跳转地址

        $this->assign('channel',cookie('channel'));
        $this->assign('znickname',cookie('znickname'));
        $this->assign('sex',cookie('zsex'));

        $this->assign('imgPath',cookie('imgPath'));
        $this->display("Xmls/ZM_zhifu");
    }
    public function jieguoye(){
        jieguoInterface();//结果页公共函数
        $this->assign('titleName',titleName('Sndy',3));//首页名称
        $user_agent = $_SERVER['HTTP_USER_AGENT'];//用户使用的浏览器，操作系统等信息。
        $channel=cookie('channel');

        if(empty($_REQUEST['ordernum'])){

        }else{
            $ordernum=$_REQUEST['ordernum'];
            $arrdata[0]=jieguoyeArrData($ordernum);
            $phone=$arrdata[0]['phone'];$this->assign('phone',$phone);
            $email=$arrdata[0]['email'];$this->assign('email',$email);
            // if($channel=='qudao100'){
            $this->assign('phonebindNum',1);//手机绑定弹窗
            $wzurl=wxJsdkData();
            $this->assign('jgOrderUrl',$wzurl);
//                $arrdata=S('sm_h5test|'.$ordernum);
//                $arrdata['phone']='';
//                $arrdata['email']='';
//                S('sm_h5test|'.$ordernum,$arrdata,2592000);//2592000为30天
            // }

            $ymd=$arrdata[0]['year'].'-'.str_pad($arrdata[0]['month'],2,"0",STR_PAD_LEFT).'-'.str_pad($arrdata[0]['day'],2,'0',STR_PAD_LEFT);
            $hour=$arrdata[0]['hour'];
            cookie('zymd',$ymd,604800);
            cookie('zhour',$arrdata[0]['hour'],604800);
            cookie('znickname',$arrdata[0]['username'],604800);
            $xingming=$arrdata[0]['username'];
            $sex=$arrdata[0]['sex'];
        }

        //一对一亲算下单
//        $QSorder=new \Library\toolOrder();
//        $wxzhifuArr=$QSorder->QSorderXD();
//        if($wxzhifuArr==1){
//            $this->assign('qsPay',1);
//        }else{//更新数据
//            if (strpos($user_agent, 'MicroMessenger') == false) {
//                //非微信浏览器访问
//            }else{
//                $this->assign('timeStamp',$wxzhifuArr['timeStamp']);
//                $this->assign('nonceStr',$wxzhifuArr['nonceStr']);
//                $this->assign('package',$wxzhifuArr['package']);
//                $this->assign('signType',$wxzhifuArr['signType']);
//                $this->assign('paySign',$wxzhifuArr['paySign']);
//                $this->assign('appId',$wxzhifuArr['appId']);
//            }
//        }

        $lenNum=mb_strlen($xingming,'utf-8');
        for($i=0;$i<$lenNum;$i++){
            $xmArr[$i]=mb_substr($xingming,$i,1,'utf-8');
        }
        $pinyinClaa=new \Library\Pinyin();
        foreach($xmArr as $key=>$value){
            $pinyinData=$pinyinClaa->str2pys($value);
            $pyArr[$key]=$pinyinData;
        }
        $dataClass=new \Library\Data();
        $xingmingLs=$dataClass->xingmingLs($pyArr,$sex);
        $Arr['xingmingLs']=$xingmingLs;

        $dataYearType=cookie('dataYearType');//2021标识

        $lnyc2020Data=new \Library\Lnyc2020Data();
        $data2020=$lnyc2020Data->index("2020-2-{$xingmingLs['number1']}",$xingmingLs['number2'],$dataYearType);
        $Arr['2020data']=$data2020;
        $this->assign('Arr',$Arr);

        $this->assign('imgPath',cookie('imgPath'));
        $this->display("Xmls/ZM_jieguoye");
    }
    public function paywx(){//H5微信支付
        H5ZMwxzhifu('XMLS','姓名灵数',cookie('orderid'),'Xmls');//知命
    }
    public function pay(){//支付宝支付
        $this->assign('ordername1','姓名灵数');
        $this->assign('ordername2','知命-姓名灵数');
        $this->display("Index/pay");
    }
}